import request from '@/config/axios'

/** 直播类型 */
export enum LiveType {
  /** 教育直播 */
  TEACH = 1,
  /** 小班课 */
  SMALL_CLASS = 2,
  /** 双师 */
  DUBBLE_TEACHER = 3,
  /** 企业直播 */
  ENTERPRISE = 4
}

/** 直播类型映射中文 */
export const LiveTypeMapper: Record<LiveType, string> = {
  [LiveType.TEACH]: '教育直播',
  [LiveType.SMALL_CLASS]: '小班课',
  [LiveType.DUBBLE_TEACHER]: '双师',
  [LiveType.ENTERPRISE]: '企业直播'
}

/** 直播类型选项 */
export const LiveTypeOptions = Object.entries(LiveTypeMapper).map(([key, value]) => ({
  label: value,
  value: key
}))

/** 直播 */
export type LiveVO = {
  id: string
  /** 直播名称 */
  liveName: string
  /** 直播描述 */
  liveDesc: string
  /** 直播类型 */
  liveType: LiveType
  /** 百家云房间id */
  roomId: string
  /** 创建时间 */
  createTime: number
  /** 更新时间 */
  updateTime: number
}

export type LivePageParam = PageParam & Partial<Pick<LiveVO, 'liveName' | 'liveType'>>

export type SearchSimplePageParam = PageParam & { liveName?: string }

export type SearchSimplePageResp = Pick<LiveVO, 'id' | 'liveName'>

export type LiveCreateDTO = Omit<LiveVO, 'id' | 'createTime' | 'updateTime'>

export type LiveUpdateDTO = Omit<LiveVO, 'createTime' | 'updateTime'>

const baseURL = '/train/course/live'

/** 分页获取直播列表，可根据liveName、liveType过滤 */
export const getPage = (params: LivePageParam) =>
  request.post<PageResult<LiveVO[]>>({
    url: `${baseURL}/page-course-live`,
    data: params
  })

/** 简单搜索数据 */
export const pageCourseLiveSearch = (data: SearchSimplePageParam) =>
  request.post<PageResult<SearchSimplePageResp>>({
    url: `${baseURL}/page-course-live-search`,
    data
  })

/** 根据id获取直播详情 */
export const get = (id: string) =>
  request.get<LiveVO>({
    url: `${baseURL}/get-course-live-detail`,
    params: { id }
  })

/** 创建直播 */
export const create = (data: LiveCreateDTO) =>
  request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })

/** 更新直播 */
export const update = (data: LiveUpdateDTO) =>
  request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })

/** 根据id删除直播 */
export const deleteById = (id: string) =>
  request.post<boolean>({
    url: `${baseURL}/delete`,
    params: { id }
  })
